package com.amumu.drama.admin.modules.order.controller;

import com.amumu.drama.admin.modules.order.service.OmsOrderService;
import com.amumu.drama.common.base.api.CommonPage;
import com.amumu.drama.common.base.api.CommonResult;
import com.amumu.drama.common.base.dto.req.IdReq;
import com.amumu.drama.common.modules.admin.dto.OmsOrderQueryParam;
import com.amumu.drama.common.modules.order.dto.req.*;
import com.amumu.drama.common.modules.order.dto.resp.OmsOrderDetailResp;
import com.amumu.drama.common.modules.order.dto.resp.OmsOrderQueryResp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单管理Controller
 * Created by macro on 2018/10/11.
 */
@RestController
@Api(tags = "微丸子-订单管理")
@RequestMapping("/order")
public class OmsOrderController {
    @Autowired
    private OmsOrderService orderService;

    @ApiOperation("微丸子-查询订单")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<OmsOrderQueryResp>> list(OmsOrderQueryParam queryParam,
                                                            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
        List<OmsOrderQueryResp> orderList = orderService.list(queryParam, pageSize, pageNum);
        return CommonResult.success(CommonPage.restPage(orderList));
    }

    @ApiOperation("订单列表查询-新")
    @PostMapping(value = "/listOrder")
    public CommonResult<CommonPage<OmsOrderQueryResp>> listOrder(@RequestBody @Validated OmsOrderQueryParam request) {
        return CommonResult.success(orderService.listOrder(request));
    }


    @ApiOperation("微丸子-查询订单详情")
    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public CommonResult<OmsOrderDetailResp> detail(@PathVariable Long id) {
        OmsOrderDetailResp orderDetailResult = orderService.detail(id);
        return CommonResult.success(orderDetailResult);
    }

    @ApiOperation("微丸子-强制接口转手工发货(谨慎调用))")
    @PostMapping(value = "forceInterfaceToManual")
    public CommonResult<Void> forceInterfaceToManuel(@RequestBody @Validated IdReq request) {
        orderService.forceInterfaceToManuel(request);
        return CommonResult.success();
    }

    @ApiOperation("微丸子-去发货(手工订单))")
    @PostMapping(value = "recharge")
    public CommonResult<Void> manualDelivery(@RequestBody @Validated AdminManualDeliveryReq request) {
        orderService.manualDelivery(request);
        return CommonResult.success();
    }

    @ApiOperation("微丸子-发货成功(手工订单))")
    @PostMapping(value = "/rechargeSuccess")
    public CommonResult<Void> manualDeliverySuccess(@RequestBody @Validated AdminDeliverySuccessReq request) {
        orderService.manualDeliverySuccess(request);
        return CommonResult.success();
    }

    @ApiOperation("微丸子-重试接口充值（强制手工转接口）")
    @PostMapping(value = "/retryInterfaceRecharge")
    public CommonResult<Void> retryInterfaceDelivery(@RequestBody @Validated AdminRetryInterfaceRechargeReq request) {
        orderService.retryInterfaceDelivery(request);
        return CommonResult.success();
    }

    @ApiOperation("微丸子-接口供应商退货")
    @PostMapping(value = "/interfaceReturn")
    public CommonResult<Void> interfaceReturn(@RequestBody @Validated AdminReturnReq request) {
        orderService.interfaceReturn(request);
        return CommonResult.success();
    }

    @ApiOperation("微丸子-支付退款")
    @PostMapping(value = "/refund")
    public CommonResult<Void> refund(@RequestBody @Validated AdminRefundReq request) {
        orderService.refund(request);
        return CommonResult.success();
    }


//    @ApiOperation("批量发货")
//    @RequestMapping(value = "/update/delivery", method = RequestMethod.POST)
//    @ResponseBody
//    public CommonResult delivery(@RequestBody List<OmsOrderDeliveryParam> deliveryParamList) {
//        int count = orderService.delivery(deliveryParamList);
//        if (count > 0) {
//            return CommonResult.success(count);
//        }
//        return CommonResult.failed();
//    }
//
//    @ApiOperation("批量关闭订单")
//    @RequestMapping(value = "/update/close", method = RequestMethod.POST)
//    @ResponseBody
//    public CommonResult close(@RequestParam("ids") List<Long> ids, @RequestParam String note) {
//        int count = orderService.close(ids, note);
//        if (count > 0) {
//            return CommonResult.success(count);
//        }
//        return CommonResult.failed();
//    }
//
//    @ApiOperation("批量删除订单")
//    @RequestMapping(value = "/delete", method = RequestMethod.POST)
//    @ResponseBody
//    public CommonResult delete(@RequestParam("ids") List<Long> ids) {
//        int count = orderService.delete(ids);
//        if (count > 0) {
//            return CommonResult.success(count);
//        }
//        return CommonResult.failed();
//    }
//
//
//    @ApiOperation("修改收货人信息")
//    @RequestMapping(value = "/update/receiverInfo", method = RequestMethod.POST)
//    @ResponseBody
//    public CommonResult updateReceiverInfo(@RequestBody OmsReceiverInfoParam receiverInfoParam) {
//        int count = orderService.updateReceiverInfo(receiverInfoParam);
//        if (count > 0) {
//            return CommonResult.success(count);
//        }
//        return CommonResult.failed();
//    }
//
//    @ApiOperation("修改订单费用信息")
//    @RequestMapping(value = "/update/moneyInfo", method = RequestMethod.POST)
//    @ResponseBody
//    public CommonResult updateReceiverInfo(@RequestBody OmsMoneyInfoParam moneyInfoParam) {
//        int count = orderService.updateMoneyInfo(moneyInfoParam);
//        if (count > 0) {
//            return CommonResult.success(count);
//        }
//        return CommonResult.failed();
//    }

    @ApiOperation("备注订单（没用的接口）")
    @RequestMapping(value = "/update/note", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult updateNote(@RequestParam("id") Long id,
                                   @RequestParam("note") String note,
                                   @RequestParam("status") Integer status) {
        int count = orderService.updateNote(id, note, status);
        if (count > 0) {
            return CommonResult.success(count);
        }
        return CommonResult.failed();
    }
}
